package br.com.admin.security;

import java.util.ArrayList;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service(value="userService")
public class UserServiceImpl  implements UserDetailsService {

	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		List<GrantedAuthority> AUTHORITIES = new ArrayList<GrantedAuthority>();		
        if(username.equals("jose")) { 
            AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_ADMIN"));
            AUTHORITIES.add(new SimpleGrantedAuthority("ROLE_USER"));
            return new User("jose", "123", AUTHORITIES); 
        } else {
            throw new UsernameNotFoundException("User not found: " + username);
        }
	}

}
